home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / PickDisplayMode.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  8KB  |  340 lines

  1. /*
  2. **    PickDisplayMode.c
  3. **
  4. **    User interface for selecting screen display modes
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16. enum    { GAD_USE=1000,GAD_CANCEL };
  17.  
  18. STATIC ULONG
  19. FilterModeID(ULONG ID,APTR UserData)
  20. {
  21.     struct DimensionInfo DimensionInfo;
  22.  
  23.     if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,ID))
  24.     {
  25.         if(DimensionInfo.MaxDepth >= (LONG)UserData && DimensionInfo.MaxDepth <= 8)
  26.             return(TRUE);
  27.     }
  28.  
  29.     return(FALSE);
  30. }
  31.  
  32.     /* PickDisplayMode(struct Window *Parent,ULONG *CurrentMode,struct Configuration *Config):
  33.      *
  34.      *    Pick a screen display mode from a list. If the Config pointer is not NULL,
  35.      *    will filter display modes out which cannot be used for the `term' main
  36.      *    screen, given the current colour restrictions.
  37.      */
  38.  
  39. BOOL
  40. PickDisplayMode(struct Window *Parent,ULONG *CurrentMode,struct Configuration *Config)
  41. {
  42.     LONG MinDepth;
  43.     BOOL Success;
  44.  
  45.     Success = FALSE;
  46.  
  47.     if(Config)
  48.     {
  49.         switch(Config->ScreenConfig->ColourMode)
  50.         {
  51.             case COLOUR_AMIGA:
  52.  
  53.                 MinDepth = 2;
  54.                 break;
  55.  
  56.             case COLOUR_EIGHT:
  57.  
  58.                 MinDepth = 3;
  59.                 break;
  60.  
  61.             case COLOUR_SIXTEEN:
  62.  
  63.                 MinDepth = 4;
  64.                 break;
  65.  
  66.             case COLOUR_MONO:
  67.  
  68.                 MinDepth = 1;
  69.                 break;
  70.         }
  71.     }
  72.  
  73.         /* For poor Workbench 2.04 users... */
  74.  
  75.     if(AslBase->lib_Version < 38)
  76.     {
  77.         struct List    *ModeList;
  78.         LONG Index;
  79.  
  80.         if(ModeList = BuildModeList(&Index,*CurrentMode,Config ? (MODEFILTER)FilterModeID : (MODEFILTER)NULL,(APTR)MinDepth))
  81.         {
  82.             struct LayoutHandle *Handle;
  83.  
  84.             if(Handle = LT_CreateHandleTags(Parent->WScreen,
  85.                 LAHN_LocaleHook,    &LocaleHook,
  86.             TAG_DONE))
  87.             {
  88.                 struct Window *LocalWindow;
  89.  
  90.                 LT_New(Handle,
  91.                     LA_Type,VERTICAL_KIND,
  92.                 TAG_DONE);
  93.                 {
  94.                     LT_New(Handle,
  95.                         LA_Type,VERTICAL_KIND,
  96.                     TAG_DONE);
  97.                     {
  98.                         LONG MaxWidth,MaxHeight,Len;
  99.                         struct Node *Node;
  100.  
  101.                         MaxWidth    = -1;
  102.                         MaxHeight    = 0;
  103.  
  104.                         for(Node = ModeList->lh_Head ; Node->ln_Succ ; Node = Node->ln_Succ)
  105.                         {
  106.                             Len = strlen(Node->ln_Name);
  107.  
  108.                             if(Len > MaxWidth)
  109.                                 MaxWidth = Len;
  110.  
  111.                             MaxHeight++;
  112.                         }
  113.  
  114.                         MaxHeight++;
  115.  
  116.                         LT_New(Handle,
  117.                             LA_Type,        LISTVIEW_KIND,
  118.                             LA_LabelID,        MSG_V36_0160,
  119.                             GTLV_Labels,    ModeList,
  120.                             LA_LONG,        &Index,
  121.                             LALV_CursorKey,    TRUE,
  122.                             LALV_Link,        NIL_LINK,
  123.                             LALV_MaxGrowY,    MaxHeight,
  124.                             LALV_ResizeY,    TRUE,
  125.                             LALV_Lines,        MaxHeight > 10 ? 10 : MaxHeight,
  126.                             LA_Chars,        MaxWidth,
  127.                             LALV_CursorKey,    TRUE,
  128.                         TAG_DONE);
  129.  
  130.                         LT_EndGroup(Handle);
  131.                     }
  132.  
  133.                     LT_New(Handle,
  134.                         LA_Type,VERTICAL_KIND,
  135.                     TAG_DONE);
  136.                     {
  137.                         LT_New(Handle,
  138.                             LA_Type,        XBAR_KIND,
  139.                             LAXB_FullSize,    TRUE,
  140.                         TAG_DONE);
  141.  
  142.                         LT_EndGroup(Handle);
  143.                     }
  144.  
  145.                     LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  146.                         LAGR_SameSize,    TRUE,
  147.                         LAGR_Spread,    TRUE,
  148.                     TAG_DONE);
  149.                     {
  150.                         LT_New(Handle,
  151.                             LA_Type,        BUTTON_KIND,
  152.                             LA_LabelID,        MSG_GLOBAL_USE_GAD,
  153.                             LA_ID,            GAD_USE,
  154.                             LABT_ReturnKey,    TRUE,
  155.                             LABT_ExtraFat,    TRUE,
  156.                         TAG_DONE);
  157.  
  158.                         LT_New(Handle,
  159.                             LA_Type,        BUTTON_KIND,
  160.                             LA_LabelID,        MSG_GLOBAL_CANCEL_GAD,
  161.                             LA_ID,            GAD_CANCEL,
  162.                             LABT_EscKey,    TRUE,
  163.                             LABT_ExtraFat,    TRUE,
  164.                         TAG_DONE);
  165.  
  166.                         LT_EndGroup(Handle);
  167.                     }
  168.  
  169.                     LT_EndGroup(Handle);
  170.                 }
  171.  
  172.                 if(LocalWindow = LT_Build(Handle,
  173.                     LAWN_TitleID,        MSG_V36_0161,
  174.                     LAWN_HelpHook,        &GuideHook,
  175.                     LAWN_Parent,        Parent,
  176.                     WA_DepthGadget,        TRUE,
  177.                     WA_DragBar,            TRUE,
  178.                     WA_RMBTrap,            TRUE,
  179.                     WA_Activate,        TRUE,
  180.                     WA_SimpleRefresh,    TRUE,
  181.                 TAG_DONE))
  182.                 {
  183.                     struct IntuiMessage    *Message;
  184.                     struct ModeNode *ModeNode;
  185.                     struct Gadget *MsgGadget;
  186.                     ULONG MsgClass;
  187.                     BOOL Done;
  188.                     LONG i;
  189.  
  190.                     Done = FALSE;
  191.  
  192.                     do
  193.                     {
  194.                         WaitPort(LocalWindow->UserPort);
  195.  
  196.                         while(Message = (struct IntuiMessage *)LT_GetIMsg(Handle))
  197.                         {
  198.                             MsgClass    = Message->Class;
  199.                             MsgGadget    = (struct Gadget *)Message->IAddress;
  200.  
  201.                             LT_ReplyIMsg(Message);
  202.  
  203.                             if(MsgClass == IDCMP_GADGETUP)
  204.                             {
  205.                                 switch(MsgGadget->GadgetID)
  206.                                 {
  207.                                     case GAD_USE:
  208.  
  209.                                         for(ModeNode = (struct ModeNode *)ModeList->lh_Head, i = 0; ModeNode->Node.ln_Succ ; ModeNode = (struct ModeNode *)ModeNode->Node.ln_Succ, i++)
  210.                                         {
  211.                                             if(Index == i)
  212.                                             {
  213.                                                 *CurrentMode = ModeNode->DisplayID;
  214.  
  215.                                                 break;
  216.                                             }
  217.                                         }
  218.  
  219.                                         Success = Done = TRUE;
  220.                                         break;
  221.  
  222.                                     case GAD_CANCEL:
  223.  
  224.                                         Done = TRUE;
  225.                                         break;
  226.                                 }
  227.                             }
  228.  
  229.                             if(MsgClass == IDCMP_IDCMPUPDATE)
  230.                             {
  231.                                 for(ModeNode = (struct ModeNode *)ModeList->lh_Head, i = 0; ModeNode->Node.ln_Succ ; ModeNode = (struct ModeNode *)ModeNode->Node.ln_Succ, i++)
  232.                                 {
  233.                                     if(Index == i)
  234.                                     {
  235.                                         *CurrentMode = ModeNode->DisplayID;
  236.  
  237.                                         Success = Done = TRUE;
  238.  
  239.                                         LT_PressButton(Handle,GAD_USE);
  240.  
  241.                                         break;
  242.                                     }
  243.                                 }
  244.                             }
  245.                         }
  246.                     }
  247.                     while(!Done);
  248.  
  249.                     if(Success && Config)
  250.                     {
  251.                         Config->ScreenConfig->Depth            = 0;
  252.                         Config->ScreenConfig->OverscanType    = OSCAN_TEXT;
  253.                         Config->ScreenConfig->DisplayWidth    = 0;
  254.                         Config->ScreenConfig->DisplayHeight    = 0;
  255.                     }
  256.                 }
  257.  
  258.                 LT_DeleteHandle(Handle);
  259.             }
  260.  
  261.             DeleteList(ModeList);
  262.         }
  263.     }
  264.     else
  265.     {
  266.         LONG DisplayWidth,DisplayHeight,Depth,OverscanType;
  267.         struct ScreenModeRequester *Request;
  268.         struct TagItem DimensionTags[5];
  269.         struct Rectangle DisplayClip;
  270.  
  271.         if(Config)
  272.         {
  273.             Depth = Config->ScreenConfig->Depth;
  274.  
  275.             if(Depth < MinDepth)
  276.                 Depth = MinDepth;
  277.  
  278.             OverscanType = Config->ScreenConfig->OverscanType;
  279.  
  280.             if((!Config->ScreenConfig->DisplayWidth || !Config->ScreenConfig->DisplayHeight) && QueryOverscan(Config->ScreenConfig->DisplayMode,&DisplayClip,OverscanType))
  281.             {
  282.                 DisplayWidth    = DisplayClip.MaxX - DisplayClip.MinX + 1;
  283.                 DisplayHeight    = DisplayClip.MaxY - DisplayClip.MinY + 1;
  284.             }
  285.             else
  286.             {
  287.                 DisplayWidth    = Config->ScreenConfig->DisplayWidth;
  288.                 DisplayHeight    = Config->ScreenConfig->DisplayHeight;
  289.             }
  290.         }
  291.         else
  292.             DisplayWidth = DisplayHeight = 0;
  293.  
  294.         if(Request = (struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
  295.             ASLSM_Window,                Parent,
  296.             ASLSM_InitialDisplayID,        *CurrentMode,
  297.             ASLSM_PrivateIDCMP,            TRUE,
  298.  
  299.             Config ? ASLSM_InitialDisplayDepth            : TAG_IGNORE,    Depth,
  300.             Config ? ASLSM_MinDepth                        : TAG_IGNORE,    MinDepth,
  301.             Config ? ASLSM_MaxDepth                        : TAG_IGNORE,    8,
  302.             Config ? ASLSM_DoDepth                        : TAG_IGNORE,    TRUE,
  303.             Config ? ASLSM_DoWidth                        : TAG_IGNORE,    TRUE,
  304.             Config ? ASLSM_DoHeight                        : TAG_IGNORE,    TRUE,
  305.             Config ? ASLSM_DoOverscanType                : TAG_IGNORE,    TRUE,
  306.             Config ? ASLSM_InitialOverscanType            : TAG_IGNORE,    OverscanType,
  307.  
  308.             DisplayWidth  ? ASLSM_InitialDisplayWidth    : TAG_IGNORE,    DisplayWidth,
  309.             DisplayHeight ? ASLSM_InitialDisplayHeight    : TAG_IGNORE,    DisplayHeight,
  310.         TAG_MORE,GetDimensionTags(Parent,DimensionTags)))
  311.         {
  312.             if(AslRequest(Request,NULL))
  313.             {
  314.                 PutDimensionTags(Parent,Request->sm_LeftEdge,Request->sm_TopEdge,Request->sm_Width,Request->sm_Height);
  315.  
  316.                 *CurrentMode = Request->sm_DisplayID;
  317.  
  318.                 if(Config)
  319.                 {
  320.                     if(Request->sm_DisplayDepth == MinDepth)
  321.                         Depth = 0;
  322.                     else
  323.                         Depth = Request->sm_DisplayDepth;
  324.  
  325.                     Config->ScreenConfig->Depth            = Depth;
  326.                     Config->ScreenConfig->OverscanType    = Request->sm_OverscanType;
  327.                     Config->ScreenConfig->DisplayWidth    = Request->sm_DisplayWidth;
  328.                     Config->ScreenConfig->DisplayHeight    = Request->sm_DisplayHeight;
  329.                 }
  330.  
  331.                 Success = TRUE;
  332.             }
  333.  
  334.             FreeAslRequest(Request);
  335.         }
  336.     }
  337.  
  338.     return(Success);
  339. }
  340.